package com.cloudsigns.factorymanager2.produce.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.iview.ICreateAccountView;
import com.cloudsigns.factorymanager2.produce.model.CreateAccountModel;
import com.cloudsigns.factorymanager2.produce.model.ICreateAccountModel;

/**
 * 创建用户
 */
public class CreateAccountPresenter {
    private ICreateAccountView view;
    private ICreateAccountModel model;
    private Handler handler = new Handler();

    public CreateAccountPresenter(ICreateAccountView view) {
        this.view = view;
        this.model = new CreateAccountModel();
    }

    public void createAccount() {
        model.createAccount(view.getRoleCategory(), view.getAvatar(), view.getAccountId(), view.getAccountName(), new CreateAccountModel.OnCreateAccountListener() {
            @Override
            public void successed() {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getCreateAccountSuccessed();
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getCreateAccountFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
